/*
 * @Author: your name
 * @Date: 2021-04-14 10:24:24
 * @LastEditTime: 2021-04-16 10:01:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /flutter_demo/lib/pages/tabs/Tabs.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_demo/pages/tabs/Category.dart';
import 'package:flutter_demo/pages/tabs/Home.dart';
import 'package:flutter_demo/pages/tabs/Setting.dart';

class TabPage extends StatefulWidget {
  final index;
  TabPage({Key key, this.index = 0}) : super(key: key);

  @override
  _TabPageState createState() => _TabPageState(this.index);
}

class _TabPageState extends State<TabPage> {
  int _currIndex;

  _TabPageState(index) {
    this._currIndex = index;
  }

  List _pageList = [HomePage(), CategoryPage(), SettingPage()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Demo'),
      ),
      drawer: Drawer(
          child: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Expanded(
                child: UserAccountsDrawerHeader(
                  accountName: Text('MMY'),
                  accountEmail: Text('labike@qq.com'),
                  currentAccountPicture: CircleAvatar(
                    backgroundImage: NetworkImage(
                        'https://t7.baidu.com/it/u=1819248061,230866778&fm=193&f=GIF'),
                  ),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                    image: NetworkImage(
                        'https://t7.baidu.com/it/u=1819248061,230866778&fm=193&f=GIF'),
                  )),
                ),
                // child: DrawerHeader(
                //   child: Text('你好 flutter'),
                //   decoration: BoxDecoration(
                //     image: DecorationImage(
                //         image: NetworkImage(
                //             'https://t7.baidu.com/it/u=1819248061,230866778&fm=193&f=GIF'),
                //         fit: BoxFit.cover),
                //   ),
                // ),
              ),
            ],
          ),
          ListTile(
            title: Text('我的空间'),
            leading: CircleAvatar(
              child: Icon(Icons.home),
            ),
          ),
          Divider(),
          ListTile(
            title: Text('用户中心'),
            leading: CircleAvatar(
              child: Icon(Icons.people),
            ),
            onTap: () {
              Navigator.of(context).pop();
              Navigator.pushNamed(context, '/user');
            },
          ),
          Divider(),
          ListTile(
            title: Text('设置'),
            leading: CircleAvatar(
              child: Icon(Icons.settings),
            ),
          )
        ],
      )),
      endDrawer: Drawer(
        child: Text('右侧抽屉'),
      ),
      floatingActionButton: Container(
        width: 60,
        height: 60,
        padding: EdgeInsets.all(10),
        // margin: EdgeInsets.only(top: 10),
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(30)),
        child: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: () {
            setState(() {
              this._currIndex = 1;
            });
          },
          backgroundColor: this._currIndex == 1 ? Colors.green : Colors.grey,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      body: this._pageList[this._currIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currIndex,
        onTap: (int index) {
          setState(() {
            this._currIndex = index;
          });
        },
        fixedColor: Colors.green,
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
              icon: Icon(
                Icons.home,
              ),
              label: '首页'),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.category,
              ),
              label: '分类'),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.settings,
              ),
              label: '设置')
        ],
      ),
    );
  }
}
